package com.example.zhongyingkaoshi.controller;

import com.example.zhongyingkaoshi.entity.Result;
import com.example.zhongyingkaoshi.utils.JwtUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.Map;

@RestController
@RequestMapping("/article")
public class ArticleController {
    @GetMapping("/list")
    public Result<String> list(@RequestHeader(name = "Authorization")String token, HttpServletResponse response) {
        //验证token
        try {
            Map<String,Object> claims = JwtUtil.parseToken(token);
            return Result.success("所有数据");
        } catch (Exception e) {
            //http状态响应码为401
            response.setStatus(401);
            return Result.error("token已过期");
        }
    }
}
